﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using DAO;
using System.Data.SqlClient;

namespace HTHTNghiepVuNhaHang.Controllers
{
    public class GeneralController : Controller
    {
        //
        // GET: /General/

        public ActionResult Index()
        {
            return View();
        }


        public ActionResult ThucDon()
        {
            int hour = DateTime.Now.Hour;
            ViewData["menu"] = LoadMenu();
            return View();

        }
        [HttpPost]
        public ActionResult ThucDon(string url)
        {
           
            return View();

        }

        public string LoadMenu()
        {

            DataTable dt = new DataTable();
            dt = LayDanhSachDanhMucChinh();

            string htmlMenu = "";
            DataTable dtbRoot = dt;
            if (dtbRoot.Rows.Count > 0)
            {
                foreach (DataRow dr1 in dtbRoot.Rows)
                {
                    htmlMenu += "<h3><a href=\"#\"><b>" + dr1["tenloaidoan"] + "</b></a></h3>";
                    DataTable dtbSub = LayDanhSachDanhMucCon( int.Parse(dr1["ID"].ToString()) );
                    if (dtbSub.Rows.Count > 0)
                    {
                        htmlMenu += "<div>";
                        foreach (DataRow dr2 in dtbSub.Rows)
                        {
                            htmlMenu += @"<li style='padding-left:3px; line-height:20px'><a href='Default.aspx'>" + dr2["tennhom"] + "</a></li>";
                        }
                        htmlMenu += "</div>";
                    }
                }
            }
            return htmlMenu;
        }

        public DataTable LayDanhSachDanhMucChinh()
        {
            ConnectionString cs = new ConnectionString();

            SqlParameter Page_Number = new SqlParameter();
            DataTable dt = new DataTable();
            dt = cs.ExecuteQuery("LayDanhSachDanhMucChinh");
            return dt;
        }

        public DataTable LayDanhSachDanhMucCon(int danhmuccha)
        {
            ConnectionString cs = new ConnectionString();
            List<SqlParameter> para = new List<SqlParameter>();
            SqlParameter danhmuc_cha = new SqlParameter();
            danhmuc_cha.SqlValue = danhmuccha;
            danhmuc_cha.ParameterName = "@danhmuccha";
            para.Add(danhmuc_cha);
            SqlParameter Page_Number = new SqlParameter();
            DataTable dt = new DataTable();
            dt = cs.ExecuteQuery("LayDanhSachDanhMucCon",para);
            return dt;
        }

    }
}
